import 'package:flutter_local_notifications/flutter_local_notifications.dart';

class NotificationUtil {
  factory NotificationUtil() => _instance;

  static final NotificationUtil _instance = NotificationUtil._();

  NotificationUtil._();

  FlutterLocalNotificationsPlugin notificationsPlugin = FlutterLocalNotificationsPlugin();

  init() async {
    var android = const AndroidInitializationSettings("@mipmap/ic_launcher");
    var ios = const DarwinInitializationSettings(requestAlertPermission: true);

    await notificationsPlugin.initialize(
        InitializationSettings(iOS: ios, android: android),
        onDidReceiveNotificationResponse: (NotificationResponse resp) {
          print("click it");
        });
  }

  Future<void> showNotification(
      {required String title, required String body }) async {
    const AndroidNotificationDetails androidNotificationDetails =
    AndroidNotificationDetails("channelId", "channelName",
        channelDescription: "this a channel Desctiption",
        importance: Importance.max, priority: Priority.high, ticker: "ticker");


    const String darwinNotificationCategoryPlain = 'plainCategory';
    const DarwinNotificationDetails darwinNotificationDetails = DarwinNotificationDetails(
        categoryIdentifier: darwinNotificationCategoryPlain
    );

    await notificationsPlugin.show(1, title, body,
       const NotificationDetails(android: androidNotificationDetails,iOS: darwinNotificationDetails));
  }


}
